import 'package:boss/models/store_area.dart';
import 'package:boss/models/store_table.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/page/tableManagement/page/tableDetail/table_detail_page.dart';
import 'package:boss/ui/page/tableManagement/widget/table_management_plus_table_card.dart';
import 'package:boss/ui/page/tableManagement/widget/table_management_table_item.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';

class TableManagementAreaCard extends StatelessWidget {
  final StoreArea data;

  const TableManagementAreaCard({
    Key key,
    @required this.data,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            padding: EdgeInsets.only(
              top: 30.w,
              left: 30.w,
            ),
            child: Text(
              data.areaName,
              style: TextStyleConstant().normal_1_36,
            ),
          ),
          GridView.builder(
            padding: EdgeInsets.symmetric(
              horizontal: 30.w,
              vertical: 30.w,
            ),
            shrinkWrap: true,
            physics: NeverScrollableScrollPhysics(),
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 3,
              childAspectRatio: 21 / 14,
              mainAxisSpacing: 30.w,
              crossAxisSpacing: 30.w,
            ),
            itemBuilder: (context, index) {
              if (index == data.storeTableList.length) {
                return TableManagementPlusTableCard(
                  onTap: () {
                    Navigator.pushNamed(context, TableDetailPage.pageName,
                        arguments: {
                          'storeArea': data,
                        });
                  },
                );
              }

              var current = data.storeTableList[index];

              return TableManagementTableItem(
                data: current,
                onTap: () {
                  Navigator.pushNamed(context, TableDetailPage.pageName, arguments: {
                    'storeArea': data,
                    'storeTable': StoreTable.fromJson(current.toJson()),
                  });
                },
              );
            },
            itemCount: data.storeTableList.length + 1,
          )
        ],
      ),
    );
  }
}
